summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt50
1 files changed, 45 insertions, 5 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt
index fde99f1a2..709a5b976 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt
@@ -1,18 +1,58 @@
+// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
package org.yuzu.yuzu_emu.model
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import org.yuzu.yuzu_emu.NativeLibrary
+import org.yuzu.yuzu_emu.utils.GameHelper
class GamesViewModel : ViewModel() {
- private val _games = MutableLiveData<ArrayList<Game>>()
- val games: LiveData<ArrayList<Game>> get() = _games
+ private val _games = MutableLiveData<List<Game>>(emptyList())
+ val games: LiveData<List<Game>> get() = _games
+
+ private val _searchedGames = MutableLiveData<List<Game>>(emptyList())
+ val searchedGames: LiveData<List<Game>> get() = _searchedGames
+
+ private val _isReloading = MutableLiveData(false)
+ val isReloading: LiveData<Boolean> get() = _isReloading
+
+ private val _shouldSwapData = MutableLiveData(false)
+ val shouldSwapData: LiveData<Boolean> get() = _shouldSwapData
init {
- _games.value = ArrayList()
+ reloadGames(false)
+ }
+
+ fun setSearchedGames(games: List<Game>) {
+ _searchedGames.postValue(games)
+ }
+
+ fun setShouldSwapData(shouldSwap: Boolean) {
+ _shouldSwapData.postValue(shouldSwap)
}
- fun setGames(games: ArrayList<Game>) {
- _games.value = games
+ fun reloadGames(directoryChanged: Boolean) {
+ if (isReloading.value == true)
+ return
+ _isReloading.postValue(true)
+
+ viewModelScope.launch {
+ withContext(Dispatchers.IO) {
+ NativeLibrary.resetRomMetadata()
+ _games.postValue(GameHelper.getGames())
+ _isReloading.postValue(false)
+
+ if (directoryChanged) {
+ setShouldSwapData(true)
+ }
+ }
+ }
}
}